<!-- 修改密码 -->
<template>
	<view class="updPass">
		<view class="no-warpper">
			<view class="nl-shadow-box">
				<view class="nl-flex-list">
					<text class="nl-margin-right">原始密码</text>
					<u-input class="input" v-model="passInfo.oldPwd" type="text" placeholder="请填写旧密码" />
				</view>
				<view class="nl-flex-list">
					<text class="nl-margin-right">新 密 码</text>
					<u-input class="input" v-model="passInfo.newPwd" type="password" placeholder="请填写新密码" />
				</view>
				<view class="nl-flex-list">
					<text class="nl-margin-right-sm">确认密码</text>
					<u-input class="input" v-model="passInfo.confirmPass" type="password" placeholder="请确认密码" />
				</view>
				<view class="button-lg" @click="changeStaffPwd()">
					<button>提交</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		changeStaffPwd
	} from 'api/user';
	import {
		mapState
	} from 'vuex';
	export default {
		components: {},
		data() {
			return {
				passInfo: {
					oldPwd: '',
					newPwd: '',
					confirmPass: ''
				}

			}
		},
		onLoad() {},
		computed: {
			...mapState('user', ['userInfo'])
		},
		methods: {
			// 修改密码
			changeStaffPwd() {
				let text = '';
				let state = '0';
				if (!this.passInfo.oldPwd && state == '0') {
					text = '请输入旧密码';
					state = '1'
				}
				if (!this.passInfo.newPwd && state == '0') {
					text = '请输入新密码';
					state = '1'
				}
				if (!this.passInfo.confirmPass && state == '0') {
					text = '请输入新密码';
					state = '1'
				}
				if ((this.passInfo.confirmPass !== this.passInfo.newPwd) && state == '0') {
					text = '两次密码不同';
					state = '1'
				}

				if (state == '1') {
					uni.showToast({
						title: text,
						icon: 'none',
						duration: 1500
					})
					return false
				}

				var that = this
				let passInfo = {
					userId: this.userInfo.userId,
					oldPwd: this.passInfo.oldPwd,
					newPwd: this.passInfo.newPwd,
				}
				changeStaffPwd(passInfo).then((res) => {
					console.log('修改密码', res)
					if (res.code == 0 && res.msg == '成功') {
						uni.showToast({
							title: '修改成功',
							icon: 'none',
							mask: true,
							duration: 3000
						});
					}

				}).catch(function(reason) {
					uni.showToast({
						title: reason.data,
						icon: 'none',
						mask: true,
						duration: 3000
					});
				})
			},
		}
	}
</script>

<style lang="scss">
</style>
